home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / ProjectDrag 1.1b4 / Sources / ProjectDrag Sources / ModifyReadOnly.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-07  |  3.9 KB  |  176 lines  |  [TEXT/MPS ]

  1. /* ModifyReadOnly.c: ModifyReadOnly applet for ProjectDrag
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13.  
  14. #include <Errors.h>
  15.  
  16. #include "DSUserProcs.h"
  17. #include "SourceServer.h"
  18. #include "PDDialogs.h"
  19. #include "Comments.h"
  20. #include "TasksAndErrors.h"
  21.  
  22.  
  23. void ModifyReadOnlyFile(FSSpec *file);
  24.  
  25.  
  26. /* This routine is called for each file passed in the ODOC event. */
  27.  
  28. pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
  29. {
  30. #pragma unused ( opening )
  31. #pragma unused ( userDataHandle )
  32.  
  33.     ModifyReadOnlyFile(myFSSPtr);
  34. }
  35.  
  36.  
  37. void ModifyReadOnlyFile(FSSpec *file)
  38. {
  39.     OSErr err;
  40.     AEDesc command;
  41.     CKIDHandle theCKID;
  42.     Str63 userName;
  43.     Str15 nickname;
  44.     Str255 comment;
  45.  
  46.     TaskStart(2001, 1, file->name, NULL, NULL, NULL);
  47.     
  48.     /* find the user name and initials */
  49.     err = GetUserSettings(userName, nickname, false);
  50.     if (err != noErr)
  51.     {
  52.         if (err != userCanceledErr)
  53.             ErrorAlert(kProjectDragStrings, kNoUserSettings, err);
  54.         gDone = true;
  55.         return;
  56.     }
  57.     
  58.     /* get the CKID */
  59.     err = ExtractCKID(file, &theCKID);
  60.     if (err != noErr)
  61.     {
  62.         RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
  63.                          NULL, NULL, NULL);
  64.         return;
  65.     }
  66.     
  67.     /* make sure the file is checked in */
  68.     if ((*theCKID)->writeable || (*theCKID)->modifyReadOnly)
  69.     {
  70.         DisposeHandle((Handle)theCKID);
  71.         RaiseErrorString(kProjectDragStrings, kNoMROPermission, file->name,
  72.                          NULL, NULL, NULL);
  73.         return;
  74.     }
  75.     
  76.     /* create a ModifyReadOnly command for SourceServer
  77.      * ModifyReadOnly <file>
  78.      */
  79.     err = CreateCommand(&command, "ModifyReadOnly");
  80.     if (err == noErr)
  81.         err = AddFileNameArg(&command,file);
  82.     if (err != noErr)
  83.     {
  84.         DisposeHandle((Handle)theCKID);
  85.         AEDisposeDesc(&command);
  86.         RaiseErrorNumber(err);
  87.         return;
  88.     }
  89.     
  90.     /* send the command to SourceServer */
  91.     err = SendCommand(&command);
  92.     if (err != noErr)
  93.     {
  94.         DisposeHandle((Handle)theCKID);
  95.         return;
  96.     }
  97.  
  98.     /* get the checkout comment from the user */
  99.     comment[0] = 0;
  100.     if (!GetChangeComment(false, file->name, comment))
  101.     {
  102.         DisposeHandle((Handle)theCKID);
  103.         return;
  104.     }
  105.  
  106.     /* add the checkout comment to the file */
  107.     err = AddCheckoutComment(file, userName, nickname, comment);
  108.     if (err != noErr)
  109.     {
  110.         Str255 projectName;
  111.  
  112.         /* pop the current task and start a new one if user confirms cancel */
  113.         if (!ResTextYesNo(kProjectDragStrings, kMROCommentFailedCancel,
  114.                          file->name, NULL, NULL, NULL))
  115.         {
  116.             RaiseErrorNumber(userCanceledErr);
  117.             return;
  118.         }
  119.         
  120.         TaskDone(); /* not really! */
  121.         
  122.         TaskStart(2001, 2, file->name, NULL, NULL, NULL);
  123.     
  124.         err = MountProjectFromCKID(theCKID, projectName);
  125.         DisposeHandle((Handle)theCKID);
  126.         if (err != noErr) return;
  127.         
  128.         /* orphan the file */
  129.         err = CreateCommand(&command, "OrphanFiles");
  130.         if (err == noErr)
  131.             err = AddFileNameArg(&command, file);
  132.         if (err != noErr)
  133.         {
  134.             AEDisposeDesc(&command);
  135.             RaiseErrorNumber(err);
  136.             return;
  137.         }
  138.         err = SendCommand(&command);
  139.         if (err != noErr) return;
  140.         
  141.         /* create the checkout command */
  142.         err = CreateCommand(&command, "CheckOut");
  143.         if (err == noErr)
  144.             err = AddPStringArg(&command, "\p-y");
  145.         if (err == noErr)
  146.             err = AddDirArg(&command, file->vRefNum, file->parID);
  147.         if (err == noErr)
  148.             err = AddProjectArg(&command, projectName);
  149.         if (err == noErr)
  150.             err = AddPStringArg(&command, file->name);
  151.         if (err != noErr)
  152.         {
  153.             AEDisposeDesc(&command);
  154.             RaiseErrorNumber(err);
  155.             return;
  156.         }
  157.         err = SendCommand(&command);
  158.         if (err != noErr) return;
  159.     }
  160.     else
  161.     {
  162.         DisposeHandle((Handle)theCKID);
  163.     }
  164.  
  165.     TaskDone();
  166. }
  167.  
  168.  
  169. void DoFileMenu(short itemID)
  170. {
  171.     if ( itemID == 1 )
  172.         SelectFile();        // call file selection userProc
  173.     else
  174.         SendQuitToSelf();    // send self a 'quit' event
  175. }
  176.